Skip to content

fix: ignore internal cost for ristretto caches#1413

Merged
Noroth merged 1 commit intomainfrom
ludwig/eng-6047-investigate-internal-cost-for-ristretto-caches
Dec 3, 2024
Merged

fix: ignore internal cost for ristretto caches#1413
Noroth merged 1 commit intomainfrom
ludwig/eng-6047-investigate-internal-cost-for-ristretto-caches

Conversation

@Noroth
Copy link
Copy Markdown
Contributor

@Noroth Noroth commented Dec 3, 2024

Motivation and Context

Ristretto caches contain an internal cost, which will be added upon each item that is supposed to be written to a cache. As an example with a cache size of 1024 and a cost per item of 1 in Set(), we would anticipate, that we could have up to 1024 items in the cache.

If IgnoreInternalCost is not set to true, for each Set operation, the provided cost will be added to an internal cost which defaults to around 56. Therefore we would have a total cost of 57 for adding a single item to the cache.

Instead of now being able to store 1024 items, we are only able to store 17 items before keys are starting to get evicted.

This PR changes the config to ignore the internal cost per cache

Warning

This change will improve the cache utilization but also have an impact on memory.
Example storing pointers to a struct with the size of 80 byte in a cache with 1024 max cost.
In theory we would then have ptr_size * struct_size * cache_size * size_of_internal_struct
8 * 80 * 1024 * 56 = 36700160 up to 36 MB of memory for this cache
(deviations possible based on OS)

Before:
On the bottom graphs we can see that the y value for the cost on the left is higher than the y value of the keys on the right.
image

After:
With the change, the cache cost will now reflect the actual number of keys.
image

Checklist

Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Noroth Noroth marked this pull request as ready for review December 3, 2024 12:24
@Noroth Noroth merged commit 94c9623 into main Dec 3, 2024
@Noroth Noroth deleted the ludwig/eng-6047-investigate-internal-cost-for-ristretto-caches branch December 3, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants